/**
 *
 * Copyright 2011 TeleNav, Inc. All rights reserved.
 * GalleryAdapter.java
 *
 */
package com.palmwindActivity.nav.gallery;

import java.util.Vector;

import com.palmwindActivity.R;
import com.palmwindActivity.app.main.LocalThumbnailAdapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.Gallery;
import android.widget.ImageView;

/**
 * @author Kane (gongchen.cn@gmail.com)
 * @date 2011-3-23
 */
public class GalleryAdapter extends BaseAdapter
{
    private Context context;
    
    private Integer[] mImageIds = 
    { R.drawable.b01, R.drawable.b02, R.drawable.b03, R.drawable.b04, R.drawable.b05};

	private Vector<Bitmap> networkingData;

	

    public GalleryAdapter(Context context, Vector<Bitmap> networkingData)
    {
        this.context = context;
        this.networkingData = networkingData;
    }

    public int getCount()
    {
    	if(networkingData != null && networkingData.size() > 0)
    	{
    		return (mImageIds.length + networkingData.size());
    	}
    	else
    	{
    		return mImageIds.length;
    	}
    }

    public Object getItem(int position)
    {
        return position;
    }

    public long getItemId(int position)
    {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent)
    {
        ImageView i = new ImageView(context);
        if(position < mImageIds.length)
        {
        	i.setImageResource(mImageIds[position]);
        }
        else
        {
        	i.setImageBitmap(networkingData.get(position - mImageIds.length));
        }
        i.setScaleType(ImageView.ScaleType.CENTER);
//        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
//            FrameLayout.LayoutParams.FILL_PARENT);
        
        ViewGroup.LayoutParams param = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        i.setLayoutParams(/* params */new Gallery.LayoutParams(param));
        
        
//        // The preferred Gallery item background
//        i.setBackgroundResource(mGalleryItemBackground);
        
        return i;
    }

}
